package com.vip.utilities;

import com.google.gson.GsonBuilder;
import com.google.gson.internal.Excluder;
import com.google.gson.internal.ObjectConstructor;

import java.lang.reflect.Type;

/**
 * Created by francis on 2016/9/26.
 */
public class JsonHelper {
    public static <T> T fromJson(String jsonString, Type objectType) {
        if (jsonString == null || jsonString.length() <= 0 || objectType == null) {
            return null;
        }
        T tmpResult = null;
        try {
            tmpResult = new GsonBuilder().create().fromJson(jsonString, objectType);
        } catch (Exception ex) {
            ex.printStackTrace();
        }
        return tmpResult;
    }

    public static String toJson(Object object) {
        if (object == null) {
            return "";
        }
        return new GsonBuilder().create().toJson(object);
    }
}
